package com.store.domain;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author yu
 * @date 2024/6/26
 * @des 统一放回结果集
 */
@Data
public class R implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 消息状态码
     */
    private int code;
    /**
     * 消息内容
     */
    private String msg;
    /**
     * 数据
     */
    private Object data;
    public static R error(String msg){
        R r = new R();
        r.setMsg(msg);
        r.setCode(300);
        return r;
    }
    public static R error(){
        return error("失败");
    }
    public static R success(String msg){
        R r = new R();
        r.setMsg(msg);
        r.setCode(200);
        return r;
    }
    public static R success(){
        return success("成功");
    }
    public static R success(Object data){
        R r = success("成功");
        r.setData(data);
        return r;
    }
    public static R success(long total, List<?> list){
        R r = success();
        Data data = new Data();
        data.setList(list);
        data.setTotal(total);
        r.setData(data);
        return r;
    }
    static class Data {
        private long total;
        private List<?> list;
        public long getTotal() {
            return total;
        }
        public void setTotal(long total) {
            this.total = total;
        }
        public List<?> getList() {
            return list;
        }
        public void setList(List<?> list) {
            this.list = list;
        }
    }
}
